package com.yt.app.api.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.yt.app.core.utils.TokenUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
@ApiModel(value = "公共参数", description = "")
public class BaseVo implements Serializable{
    @ApiModelProperty(value = "token, 需要登陆接口此参数必传", required = false)
    public String token;
    @ApiModelProperty(value = "平台：android，iphone", required = false)
    public String platform;
    @ApiModelProperty(value = "网络类型：0：wifi 2：2G ,3:3G , 4:4G, 5:5G,-1:网络不可用， 1：没有网络", required = false)
    private String networktype;
    @ApiModelProperty(value = "客户端版本", required = false)
    private String ver;
    @ApiModelProperty(value = "纬度", required = false)
    private String latitude;
    @ApiModelProperty(value = "经度", required = false)
    private String longitude;
    @ApiModelProperty(value = "IP", required = false)
    private String ip;
    @ApiModelProperty(value = "ANDROID ID", required = false)
    private String androidid;
    @ApiModelProperty(value = "imei", required = false)
    private String imei;
    @ApiModelProperty(value = "Sdk版本", required = false)
    private String sdkver;
    @ApiModelProperty(value = "手机型号", required = false)
    private String model;
    @ApiModelProperty(value = "系统版本", required = false)
    private String releasever;
    @ApiModelProperty(value = "MAC地址", required = false)
    private String mac;
    @ApiModelProperty(value = "IDFA", required = false)
    private String idfa;
    @ApiModelProperty(value = "渠道", required = false)
    private String channel;

    @JSONField(serialize = false)
    private Long uid;

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public String getNetworktype() {
        return networktype;
    }

    public void setNetworktype(String networktype) {
        this.networktype = networktype;
    }

    public String getVer() {
        return ver;
    }

    public void setVer(String ver) {
        this.ver = ver;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getAndroidid() {
        return androidid;
    }

    public void setAndroidid(String androidid) {
        this.androidid = androidid;
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public String getSdkver() {
        return sdkver;
    }

    public void setSdkver(String sdkver) {
        this.sdkver = sdkver;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getReleasever() {
        return releasever;
    }

    public void setReleasever(String releasever) {
        this.releasever = releasever;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    public String getIdfa() {
        return idfa;
    }

    public void setIdfa(String idfa) {
        this.idfa = idfa;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public static Long getUIDFromHeader(HttpServletRequest request){
        try {
            String token = request.getHeader("x-access-token");
            return TokenUtil.getUIDFromToken(token);
        }catch (Exception ex){}
        return null;
    }
}
